Objectives

By the end of this session, you should be able to:

  • State the benefits of a reproducible analysis
  • Login to your RStudio instance and explain the layout
  • Illustrate the use of the Markdown language
  • Explain how to seek help and create a reproducible example

Reproducibility

Workflows

Simplified Model

Tools

  • RStudio: provides a nicer interface for using R and an authoring framework for data science
  • LaTeX: helps behind the scenes to knit to PDF and offers more control over typesetting
  • Zotero, BibDesk, and .bib files: manage references

Using Duke’s Docker-ized version of RStudio Server

In this workshop, we will use RStudio via the web.

RStudio Interface

RStudio Interface

Projects

Never hardcode a working directory again!

  • Click on Projects
  • Choose to create a new project
  • Follow the prompt to create a new directory called “ieat”

Organization

Organization

New files

R script

Create a new R script file

  • similar to Stata’s do file
  • not interactive
  • output appears in console and plot window

RMarkdown

Create a new RMarkdown HTML file

Markdown language

Plain text, *italics*, **bold**, `monospaced font`

~~strikethrough~~, sub/superscript^2^~2~, endash: --, emdash: ---
  
equation: $A = \pi*r^{2}$
  
$$E = mc^{2}$$
  
> block quote 
  
list:
  
  * item 1
  * item 2
  * item 3

Markdown Language

Plain text, italics, bold, monospaced font

strikethrough, sub/superscript22, endash: –, emdash: —

equation: \(A = \pi*r^{2}\)

\[E = mc^{2}\]

block quote

list:

  • item 1
  • item 2
  • item 3

Getting help

An unexpected result!

x <- c(4, 2, 6, 9, 2, 5, 4, 3, 7, 6, 8, 4, 7, 2, NA, 3)
x_mean <- mean(x)
x_mean
## [1] NA

?function

?mean

Stack Overflow

Bad questions

Reproducible Example